<script setup>

import { onMounted, ref } from 'vue';
import { useNewAndHotStore } from '@/stores/goodsStore'

//创建实例
const NewAndHotStore = useNewAndHotStore();
//用狗子函数调用实例中的方法（上边要导入相应的包）
onMounted(
    () => NewAndHotStore.getNewAndHot()
)



</script>


<template>
    <div class="goods-hot">
        <h3>新鲜好物</h3>
        <!-- 商品区块 -->
        <RouterLink :to="`/detail/${item.id}`" class="goods-item" v-for="item in NewAndHotStore.NewAndHotList.newGoods?.slice(0, 2)"
            :key="item.id">
            <img :src="item.goodsImg" alt="" />
            <p class="name ellipsis">{{ item.goodsName }}</p>
            <p class="desc ellipsis">{{ item.content }}</p>
            <p class="price">&yen;{{ item.price }}</p>
        </RouterLink>
    </div>
    <div class="goods-hot">
        <h3>人气推荐</h3>
        <!-- 商品区块 -->
        <RouterLink :to="`/detail/${item.id}`" class="goods-item" v-for="item in NewAndHotStore.NewAndHotList.hotGoods?.slice(0, 2)"
            :key="item.id">
            <img :src="item.goodsImg" alt="" />
            <p class="name ellipsis">{{ item.goodsName }}</p>
            <p class="desc ellipsis">{{ item.content }}</p>
            <p class="price">&yen;{{ item.price }}</p>
        </RouterLink>
    </div>
</template>


<style scoped lang="scss">
.goods-hot {
    h3 {
        height: 70px;
        background: $helpColor;
        color: #fff;
        font-size: 18px;
        line-height: 70px;
        padding-left: 25px;
        margin-bottom: 10px;
        font-weight: normal;
    }

    .goods-item {
        display: block;
        padding: 20px 30px;
        text-align: center;
        background: #fff;
        width: 280px;

        img {
            width: 160px;
            height: 160px;
        }

        p {
            padding-top: 10px;
        }

        .name {
            font-size: 16px;
        }

        .desc {
            color: #999;
            height: 29px;
        }

        .price {
            color: $priceColor;
            font-size: 20px;
        }
    }
}
</style>